
package spil;

import desktop_resources.GUI;

public class LaborCamp extends Ownable {
	protected int rent;
	protected int price;
	private static Dice d1 = new Dice();

	public LaborCamp(int price, int fieldNumber) {
		super(price, fieldNumber);
		this.rent = rent;
		this.price = price;
	}

	public void landOnField(Player p) {
		if(owner == null) {
			boolean buy = GUI.getUserLeftButtonPressed(title + " er ikke ejet", "køb", "ignorer");
			if(buy) {
				if(p.getBalance() > price)
					p.addCamp();
				buy(p);
			}
			else GUI.getUserButtonPressed(p + " købte ikke " + title, "ok");
		}
		else {
			d1.roll();
			rent = d1.getSum() * 10 * owner.getCamps();
			GUI.setDice(d1.getd1(), d1.getd2());
			if(p != owner) {
				if(p.getAccount().getBalance() < rent) {
					GUI.getUserButtonPressed(p + " betaler " + p.getBalance() + "\n til " + owner, "ok");
					owner.getAccount().insert(p.getBalance());
					p.getAccount().withdraw(p.getBalance());
				}
				else {
					GUI.getUserButtonPressed(p + " betaler " + rent + "\n til " + owner, "ok");
					p.getAccount().withdraw(rent);
					owner.getAccount().insert(rent);
				}
			}
			else GUI.getUserButtonPressed(owner + " ejer " + title, "ok");
		}
	}

	public int getRent() {
		return rent;
	}

	public String toString() {
		if(owner != null)
			return title + " er ejet af " + owner + "\nLejen er " + rent;
		return title + " er ikke ejet" ;
	}
}
